// app.js
App({
  util: require('/utils/util.js'),
  api: require('/utils/api.js'),
  httputil: require('utils/httputil.js'),

  encrypt: require('/utils/jsencrypt.js'),

  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {
    userInfo: null,
    Authorization: '',
    accountType: '',
    phone: '',
    MerchantStoreInfo: null
  },


  /**
   * 保存userInfo
   * @param {*} data 
   */
  saveUserInfo: function (data) {
    this.globalData.userInfo = data
  },

  /**
   * 保存Token
   * @param {*} data 
   */
  saveToken: function (data) {
    this.globalData.Authorization = data
  },

  /**
   * 保存phone
   * @param {*} data 
   */
  savePhone: function (data) {
    this.globalData.phone = data
  },

  /**
   * 保存accountType
   * @param {*} data 
   */
  saveAccountType: function (data) {
    this.globalData.accountType = data
  },

  /**
   * 保存门店信息
   * @param {*} data 
   */
  saveMerchantStoreInfo: function (data) {
    this.globalData.MerchantStoreInfo = data
  },


  px2rpx: function (pxValue) {
    const designWidth = 750;

    // 获取屏幕宽度
    const screenWidth = wx.getSystemInfoSync().screenWidth;

    // 计算 px 到 rpx 的转换比例
    const pxToRpxScale = designWidth / screenWidth;

    // 动态计算 rpx 值
    const rpxValue = pxValue * pxToRpxScale;
    return rpxValue
  },

  rpx2px: function (rpxValue) {
    const designWidth = 750;

    // 获取屏幕宽度
    const screenWidth = wx.getSystemInfoSync().screenWidth;

    // 计算 px 到 rpx 的转换比例
    const pxToRpxScale = designWidth / screenWidth;

    // 动态计算 rpx 值
    const pxValue = rpxValue / pxToRpxScale;
    return pxValue
  }
})